{include file="common/header" /}
<link rel="stylesheet" href="__LAYUIMINI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<style>
    body {
        background-color: #ffffff;
    }
    .layui-form-label {
        width: 150px;
    }
    .layui-input-block{
        margin-left: 150px;
    }
</style>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>模型修改</legend>
</fieldset>
<div class="layui-form layuimini-form">
      <div class="layui-form-item">
        <label class="layui-form-label">模型名称</label>
        <div class="layui-input-block" style="width:500px;">
          <input type="text" class="layui-input" lay-verify="required" name="title" value="{$info.title}" autocomplete="off" placeholder="请输入模型名称" >
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">表名</label>
        <div class="layui-input-block" style="width:500px;">
          <input disabled type="text" class="layui-input" lay-verify="required" name="name" value="{$info.name}" autocomplete="off" placeholder="请输入表名" >
        </div>
      </div>
     
     <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" >描述</label>
        <div class="layui-input-block" style="width:610px;">
          <textarea name="description" placeholder="请输入描述" class="layui-textarea field-description">{$info.description}</textarea>
        </div>
      </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否允许删除数据</label>
        <div class="layui-input-block">
            <div class="switch">
                <input type="checkbox" lay-filter="sw" name="isdel" lay-skin="switch" lay-text="是|否" data-name="isdel" data-check="1" data-nocheck="0"{if $info.isdel == 1} checked{/if}>
            </div>
            <input name="isdel" type="hidden" value="{$info.isdel}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否允许添加数据</label>
        <div class="layui-input-block">
            <div class="switch">
                <input type="checkbox" lay-filter="sw" name="isadd" lay-skin="switch" lay-text="是|否" data-name="isadd" data-check="1" data-nocheck="0"{if $info.isadd == 1} checked{/if}>
            </div>
            <input name="isadd" type="hidden" value="{$info.isadd}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
          <input type="radio" name="type" value="1" title="列表显示" {if $info.type == 1 /} checked=""{/if}>
          <input type="radio" name="type" value="2" title="单页显示" {if $info.type == 2 /} checked=""{/if}>
        </div>
    </div>
      
      <div class="layui-form-item">
        <div class="layui-input-block">
          <input type="hidden" name="id" value="{:input('param.id')}">
          <button class="layui-btn" lay-submit lay-filter="saveBtn">立即提交</button>
          <a href="{:url('index')}" class="layui-btn layui-btn-primary">返回</a>
        </div>
      </div>
</div>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        form.on('switch(sw)', function(data){
            var obj=data.elem;
            if(data.elem.checked){
                var value=$(obj).attr('data-check');
            }else{
                var value=$(obj).attr('data-nocheck');
            }
            var name=$(obj).attr("data-name");
            $("input[name='"+name+"']").val(value);
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;
            // console.log(data)
            // return false
            $.ajax({
                url:"{:url('module/edit')}",
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    // console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            window.location.href = "{:url(CONTROLLER_NAME.'/index')}";
                        })
                    }
                    layer.close(index);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>

</html>